<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>附近商家</title>
		<script src="__INDEX__/js/mui.min.js"></script>
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__INDEX__/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
		<link rel="stylesheet" href="__INDEX__/css/mall.css" />
		<script src="__PUBLIC__/static/js/jquery.min.js"></script>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
		    <h1 class="mui-title">附近商家</h1>
		</header>
		
		<div class="mui-content">
			<div class="shoplist_top">
				<div class="slist_address">
					<span class="mui-icon iconfont icon-refurbish"></span>
					<div><span class="mui-icon iconfont icon-dingwei" id="address"></span></div>
				</div>
			</div>
			<div class="shoplist_box">
				<ul class="index_sjlist" id="store_ul">
					
				</ul>
			</div>
		</div>
		<div id="allmap"></div>
		{include file="public/bottom" /}
	</body>

</html>
{include file="public/footer" /}
<script src="__PUBLIC__/static/js/assist.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.2&key=eef7f290ac06bdf05b246cebc8cb2fb6&callback=my_getAddress"></script>
<script src="__PUBLIC__/static/js/help.js "></script>
<script src="__PUBLIC__/static/js/assist.js "></script>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js "></script>
<script type="text/javascript">
//获取用户当前地址
var map, geolocation;
	get_data(0,0);
function my_getAddress(){
	var longitude = getCookie('longitude');
	var latitude = getCookie('latitude');
	
	if(longitude && latitude){
		get_data(longitude,latitude);
	}else{
		//加载地图，调用浏览器定位服务
	    map = new AMap.Map('container', {
	        resizeEnable: true
	    });
	    map.plugin('AMap.Geolocation', function() {
	        geolocation = new AMap.Geolocation({
	            enableHighAccuracy: true,//是否使用高精度定位，默认:true
	            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
	            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
	            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
	            buttonPosition:'RB'
	        });
	        map.addControl(geolocation);
	        geolocation.getCurrentPosition();
	        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
	        if(!getCookie('longitude') || getCookie('longitude')<0){
	        	//get_data(113.015137,113.015137);
	        }
	        
	        
	    });
	    $('#container').hide();
	}
	
    //解析定位结果
    function onComplete(data) {
    	setCookie('longitude',data.position.getLng());
    	setCookie('latitude',data.position.getLat());
    	get_data(data.position.getLng(),data.position.getLat());
    }
}
    function get_data(lng,lat){
    	$.ajax({
		   	type:"post",
		   	data:{
		   		longitude	: lng,
		   		latitude	: lat
		   	},
		   	url:"{:url('index/index/get_agents')}",
		   	success:function(data){
		   		var html="";
		   		if(data.list){
		   			var list=data.list;
		   			for(var o in list){
		   				var agent=list[o];
		   				var juli = agent.juli;
		   				var diz = agent.address;
		   				var begin_time = ''
		   				var end_time = '';
		   				var dk=0;
		   				var unit ='m';
		   				if(agent.is_score==1){
		   					dk=agent.ad_score;
		   				}
		   				var action=agent['action'];
		   				if(action==null){
		   					action="暂无";
		   				}
		   				if(juli>1000){
		   					juli = juli/1000;
		   					unit = 'km';
		   				}
		   				if(diz && diz.length>0){
		   					diz = diz.replace('郴州市', '');
		   					diz = diz.replace('湖南省', '');
		   				}else{
		   					diz = '暂无';
		   				}
		   				if(agent.start_time && agent.start_time.length>0){
		   					begin_time = agent.start_time.substr(0,agent.start_time.length-3);
		   				}else{
		   					begin_time = '00:00';
		   				}
		   				if(agent.end_time && agent.end_time.length>0){
		   					end_time = agent.end_time.substr(0,agent.end_time.length-3);;
		   				}else{
		   					end_time = '00:00';
		   				}
		   				var logo=agent.logo;
		   				if(!logo){
		   					logo="__PUBLIC__/static/index/images/noimage.jpg";
		   				}
		   				
		   				
		   				var agent_name = agent.agent_name;
						html="<li>"
							  +"<a href='/index/index/shop_info?agent_id="+agent.id+"' class='clearfix'>"
							  +"<div class='index_sjimg'><img src='"+logo+"'></div>"
							  +"<div class='index_sjinfo'>"
							  +"<div class='index_spname'>"+agent_name+"</div>"
							  +"<div class='index_spstyle clearfix'>"
							  +"<span class=''>鼓励金最高可抵:<span style='color:red;font-weight:600;'>"+dk+"%</span></span>"
							  +"<span class='index_sjdw' style='float: right;'><i class='iconfont'></i>"+juli+unit+"</span>"
							  +"</div><div class='index_spstyle clearfix'>"+diz+"</div>"
							  +"</div></a>"
							  +"<div class='shopzxhd'><span style='color:#666666;'>最新活动&nbsp;:&nbsp;</span><span style='margin-left:5px'>"+action+"</span></div>"
							  +"</li>";
					$('#store_ul').append(html);
					}
		   			//$("#store_ul").html(html);
		   		}else{
		   			$("#store_ul").html("<li>附近无商铺<li>");
		   		}
		   	}
		});
    }

	mui.init();
	var aniShow = "pop-in";
	//页面跳转
	mui('#footer-list').on('tap', 'a', function() {
		var id = this.getAttribute('href');
		var href = this.href;
		mui.openWindow({
			id: id,
			url: this.href,
			show: {
				aniShow: aniShow
			},
			waiting: {
				autoShow: false
			}
		});
	});
		
	
</script>
